Adding a Theme Color

Adding a new colour to Blender's GUI theme system is quite easy, but involves a few steps. I've catalogued them here as a quick walk-through. In this example I'm adding theme colours for the various types of sequence editor strips.

1. Define names for the theme colours

Here we need to give the theme colours defined names so we can refer to them in our code.

source/blender/include/ BIF_resources.h

Add to the end of enum { TH_AUTO, TH_BUT_OUTLINE, ... } your new theme colours, following the same naming scheme. Colours that are used in the GUI (i.e. consistent across window space types) should be added before the TH_THEMEUI define. Other window space specific colours should be added at the end.

2. Create variables to store the colours in

source/makesdna/DNA_userdef_types.h

This file contains the structs that get saved in SDNA, to the .B.blend user settings file. You need to add variables here to store the theme colours in when they are saved in the file. If the the colour you're adding is a cross-space UI theme colour, add the necessary variables to struct ThemeUI, otherwise add them to struct ThemeSpace.

You will need to follow the DNA struct padding rules here.

3. Set up theme API and define colour values for the default theme

source/src/resources.c

BIF_ThemeGetColorPtr() is the function that finds the right colour values in the User Preferences struct based on the theme colour name. Find BIF_ThemeGetColorPtr() and add in the appropriate code, referencing the variables you just made in DNA_userdef_types.h . Again, refer to the existing code, and add your theme colours in the same places, depending on whether they are UI theme colours or window space theme colours.